package cn.blnp.net.flowable.listen.global.events;

import cn.blnp.net.flowable.config.FlowableLoggingListener;
import cn.hutool.core.map.MapUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.*;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <h3>全局事件监听器</h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/5/21 15:14
 */
@Slf4j
@SpringBootTest
public class GlobalEventFlowTest {

    @Resource
    private RepositoryService repositoryService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    private TaskService taskService;
    @Resource
    private HistoryService historyService;
    @Resource
    private ManagementService managementService;

    /**
     *  <h2>工作原理</h2>
     *  <p>
     *   &emsp;&emsp;全局事件监听器是引擎级别的，既可以注册在全部事件类型上，也可以注册在指定的事件类型上。监听器与事件的注册是在工作流引擎启动时完成的。全局事件监听器的工作原理是，
     *   在流程运行过程中，当某一个事件被触发时，工作流引擎会根据事件的类型匹配对应的监听器进行处理。<br/>
     *   <img src="https://cdn4.winhlb.com/2025/05/21/682d7ea2e9ecc.png" />
     *  </p>
     **/
    @Test
    public void testBase() {

    }

    /**
     *  <h2>支持的事件类型</h2>
     *  <p>
     *   &emsp;&emsp;Flowable引擎内置了多种事件类型，每种类型都对应 {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType}中的一个枚举值。Flowable工作流引擎内置
     *   的事件名称及事件类型如下所示：
     *   <ol>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENTITY_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li>
     *                   <b>事件描述：</b>创建了一个新实体。实体包含在事件中，可以从事件中获取实体
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENTITY_INITIALIZED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li>
     *                   <b>事件描述：</b>创建了一个新实体，初始化也完成了。如果该实体的创建包含子实体的创建，则该事件会在子实体都创建/初始化完成后被触发，这是它与ENTITY_CREATED的区别
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENTITY_UPDATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>更新了已存在的实体。实体包含在事件中，可以从事件中获取实体</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENTITY_DELETED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>删除了已存在的实体。实体包含在事件中，可以从事件中获取实体</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENTITY_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b></li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENTITY_SUSPENDED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li>
     *                   <b>事件描述：</b>挂起了已存在的实体。实体包含在事件中，可以从事件中获取实体。该事件可以被ProcessDefinition、ProcessInstance和Task抛出
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENTITY_ACTIVATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li>
     *                   <b>事件描述：</b>激活了已存在的实体，实体包含在事件中，可以从事件中获取实体。该事件可以被ProcessDefinition、ProcessInstance和Task抛出
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TIMER_SCHEDULED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>定时器作业被创建</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TIMER_FIRED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>触发了定时器。Job对象包含在事件中</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#JOB_CANCELED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li>
     *                   <b>事件描述：</b>取消了一个作业。事件包含取消的作业。作业可以在以下3种情况下取消：通过API调用取消；在任务完成后取消对应的边界定时器；新流程定义发布时取消旧版本流程定
     *                   义中定时器开始事件对应的定时器
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#JOB_EXECUTION_SUCCESS}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>作业执行成功。Job对象包含在事件中</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#JOB_EXECUTION_FAILURE}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent、FlowableExceptionEvent</li>
     *               <li><b>事件描述：</b>作业执行失败。作业和异常信息包含在事件中</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#JOB_RETRIES_DECREMENTED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>因为作业执行失败，重试次数减少。作业包含在事件中</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#JOB_REJECTED}
     *           <ul>
     *               <li><b>事件类型：</b>无</li>
     *               <li><b>事件描述：</b>作业被异步执行器拒绝，通常原因是队列已满</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#JOB_RESCHEDULED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableJobRescheduledEvent</li>
     *               <li><b>事件描述：</b>作业被重新执行</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#JOB_MOVED_TO_DEADLETTER}
     *           <ul>
     *               <li><b>事件类型：</b>无</li>
     *               <li><b>事件描述：</b>作业被转为死信作业，通常意味着重试的次数已耗尽</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#CUSTOM}
     *           <ul>
     *               <li><b>事件类型：</b>无</li>
     *               <li><b>事件描述：</b>自定义事件</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENGINE_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEven</li>
     *               <li><b>事件描述：</b>监听器监听的工作流引擎已经创建完毕，并准备接受API调用</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ENGINE_CLOSED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEvent</li>
     *               <li><b>事件描述：</b>监听器监听的工作流引擎已经关闭，不再接受API调用</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_STARTED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableActivityEvent</li>
     *               <li><b>事件描述：</b>一个节点开始执行</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_COMPLETED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableActivityEvent</li>
     *               <li><b>事件描述：</b>一个节点成功完成</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_CANCELLED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableActivityCancelledEvent</li>
     *               <li>
     *                   <b>事件描述：</b>节点将要取消。节点可以被MessageEvent、SubscriptionEntity、SignalEventSubscriptionEntity、TimerEntity等取消
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#MULTI_INSTANCE_ACTIVITY_STARTED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableMultiInstanceActivityEvent</li>
     *               <li><b>事件描述：</b>多实例节点开始执行</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#MULTI_INSTANCE_ACTIVITY_COMPLETED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableMultiInstanceActivityCompletedEvent</li>
     *               <li><b>事件描述：</b>多实例节点的所有实例都已完成，不考虑实例的条件。即使未满足完成条件，也会被触发</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#MULTI_INSTANCE_ACTIVITY_COMPLETED_WITH_CONDITION}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableMultiInstanceActivityCompletedEvent</li>
     *               <li><b>事件描述：</b>完成条件满足，多实例节点已完成，但不考虑实例是否都完成。只有满足完成条件，才会被触发</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#MULTI_INSTANCE_ACTIVITY_CANCELLED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableMultiInstanceActivityCancelledEvent</li>
     *               <li><b>事件描述：</b>多实例节点将要取消。多实例节点可以被MessageEventSubscriptionEntity、SignalEvent、SubscriptionEntity、TimerEntity等取消</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_SIGNAL_WAITING}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableSignalEvent</li>
     *               <li><b>事件描述：</b>一个节点在等待信号</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_SIGNALED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableSignalEvent</li>
     *               <li><b>事件描述：</b>一个节点收到了一个信号</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_COMPENSATE}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableActivityEvent</li>
     *               <li><b>事件描述：</b>一个节点将要被补偿。事件包含了将要执行补偿的节点ID</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_CONDITIONAL_WAITING}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableConditionalEvent</li>
     *               <li><b>事件描述：</b>一个节点在等待条件满足</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_CONDITIONAL_RECEIVED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableConditionalEvent</li>
     *               <li><b>事件描述：</b>一个节点等待的条件被满足</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_ESCALATION_WAITING}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEscalationEvent</li>
     *               <li><b>事件描述：</b>一个节点在等待升级</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_ESCALATION_RECEIVED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEscalationEvent</li>
     *               <li><b>事件描述：</b>一个节点接收到升级</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_MESSAGE_WAITING}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableMessageEvent</li>
     *               <li><b>事件描述：</b>一个节点已经创建了一个消息事件订阅，并正在等待接收消息</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_MESSAGE_RECEIVED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableMessageEvent</li>
     *               <li>
     *                   <b>事件描述：</b>节点收到了一个消息。事件在节点接收消息前分发。节点接收消息后，会为该节点分发ACTIVITY_SIGNALED或ACTIVITY_STARTED事件，取决于其类型（边界事件，或子流程启动事件）
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_MESSAGE_CANCELLED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableMessageEvent</li>
     *               <li><b>事件描述：</b>个节点已经取消了一个消息事件订阅，因此接收这个消息不会再触发该节点</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#ACTIVITY_ERROR_RECEIVED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableErrorEven</li>
     *               <li><b>事件描述：</b>节点收到了错误事件。在节点实际处理错误前分发。该事件的activityId为处理错误的节点。如果错误成功传递，后续会为节点发送ACTIVITY_ SIGNALED或ACTIVITY_COMPLETE消息</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#HISTORIC_ACTIVITY_INSTANCE_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>历史活动实例被创建</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#HISTORIC_ACTIVITY_INSTANCE_ENDED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>历史活动实例已结束</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#SEQUENCEFLOW_TAKEN}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableSequenceFlowTakenEvent</li>
     *               <li><b>事件描述：</b>一个顺序流被执行</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#VARIABLE_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableVariableEvent</li>
     *               <li><b>事件描述：</b>创建了一个变量。事件包含变量名称、变量值和对应的分支或任务（如果存在）</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#VARIABLE_UPDATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableVariableEvent</li>
     *               <li><b>事件描述：</b>更新了一个变量。事件包含变量名称、变量值和对应的分支或任务（如果存在）</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#VARIABLE_DELETED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableVariableEvent</li>
     *               <li><b>事件描述：</b>删除了一个变量。事件包含变量名称、变量值和对应的分支或任务（如果存在）</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TASK_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>创建了新任务并且任务的所有属性都已设置。它位于ENTITY_CREATED事件之后。当任务是由流程创建时，该事件会在TaskListener执行之前被执行</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TASK_ASSIGNED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>任务已经分派给了用户。该任务包含在本事件里</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TASK_COMPLETED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li>
     *                   <b>事件描述：</b>任务完成。它会在ENTITY_DELETED事件之前触发。当任务是流程的一部分时，事件会在流程继续流转之前触发，其后续事件将是ACTIVITY_COMPLETED，对应完成
     *                   任务的节点
     *               </li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TASK_OWNER_CHANGED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>用户任务的owner属性发生变化</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TASK_PRIORITY_CHANGED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>用户任务的priority属性发生变化</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TASK_DUEDATE_CHANGED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>用户任务的dueDate属性发生变化</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#TASK_NAME_CHANGED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>用户任务的name属性发生变化</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#PROCESS_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>流程实例已经创建。已经设置所有的基础参数，但还未设置变量</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#PROCESS_STARTED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableProcessStartedEvent</li>
     *               <li><b>事件描述：</b>流程实例已经启动。在启动之前创建流程时分发。PROCESS_STARTED事件在相关的ENTITY_INITIALIZED事件，以及设置变量之后分发</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#PROCESS_COMPLETED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>流程已结束，在最后一个节点的ACTIVITY_ COMPLETED事件之后触发。当流程实例没有任何路径可以继续时，流程结束</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#PROCESS_COMPLETED_WITH_TERMINATE_END_EVENT}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableProcessTerminatedEven</li>
     *               <li><b>事件描述：</b>流程已经到达终止结束事件并结束</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#PROCESS_COMPLETED_WITH_ERROR_END_EVENT}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>流程已经到达错误结束事件并结束</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#PROCESS_COMPLETED_WITH_ESCALATION_END_EVENT}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>流程已经到达升级结束事件并结束</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#PROCESS_CANCELLED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableCancelledEvent</li>
     *               <li><b>事件描述：</b>流程已经被取消。在流程实例从运行时中删除前分发。流程实例由API调用RuntimeService的deleteProcessInstance()方法取消</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#HISTORIC_PROCESS_INSTANCE_CREATED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>历史流程实例创建完成</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#HISTORIC_PROCESS_INSTANCE_ENDED}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableEntityEvent</li>
     *               <li><b>事件描述：</b>历史流程实例成功结束</li>
     *           </ul>
     *       </li>
     *       <li>
     *           {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType#CHANGE_TENANT_ID}
     *           <ul>
     *               <li><b>事件类型：</b>FlowableChangeTenantIdEven</li>
     *               <li><b>事件描述：</b>切换业务方</li>
     *           </ul>
     *       </li>
     *   </ol>
     *   除此之外Flowable的身份管理引擎中也内置了一系列的事件，每种类型都对应 {@link org.flowable.idm.api.event.FlowableIdmEventType}中的一个枚举值，由于篇幅的原因这
     * 里不进行介绍。 {@link org.flowable.common.engine.api.delegate.event.FlowableEngineEventType}和 {@link org.flowable.idm.api.event.FlowableIdmEventType}都实现了
     * {@link org.flowable.common.engine.api.delegate.event.FlowableEventType}接口。
     *  </p>
     **/
    @Test
    public void testEventType() {

    }

    /**
     *  <h2>案例演示</h2>
     *  <p>
     *      常规流程：{@link flow/globalEventFlow.bpmn20.xml}
     *  </p>
     **/
    @Test
    public void testExample() {
        /**
         *  特别说明：
         *  1、该流程为普通流程，没有任何配置。仅指定了部分全局事件配置。详见：{@link cn.blnp.net.flowable.config.FlowableConfig}，监听
         *  实现详见：{@link cn.blnp.net.flowable.config.GlobalEventListener}
         **/
        Deployment deploy = repositoryService.createDeployment()
                .name("普通流程-演示案例")
                .addClasspathResource("flow/globalEventFlow.bpmn20.xml")
                .deploy();
        log.info("部署流程定义：{}", deploy.getId());
        ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery()
                .deploymentId(deploy.getId())
                .singleResult();
        log.info("流程定义编号：{}", procDef.getId());
        //设置流程变量
        Map<String, Object> varMap1 = MapUtil.builder(new HashMap<String, Object>())
                .put("lender", "张三")
                .build();
        //启动流程实例
        ProcessInstance procInst = runtimeService.startProcessInstanceById(procDef.getId(), varMap1);
        //查询任务
        Task task = taskService.createTaskQuery()
                .processInstanceId(procInst.getId()).singleResult();
        //办理任务
        taskService.complete(task.getId());

        /**
         *  演示结果：
         *  2025-05-22 13:46:30.733  INFO 24128 --- [           main] c.b.n.f.l.g.events.GlobalEventFlowTest   : 部署流程定义：1bee618a-36d0-11f0-ac1a-50ebf6ec8f6d
         * 2025-05-22 13:46:30.737  INFO 24128 --- [           main] c.b.n.f.l.g.events.GlobalEventFlowTest   : 流程定义编号：globalEventFlow:2:1c70b0ed-36d0-11f0-ac1a-50ebf6ec8f6d
         * 2025-05-22 13:46:30.810  INFO 24128 --- [           main] c.b.n.f.config.GlobalEventListener       : GlobalEventListener: TASK_CREATED
         * 2025-05-22 13:46:30.810  INFO 24128 --- [           main] c.b.n.f.config.GlobalEventListener       : 用户任务sid-3F4DC69F-9435-4D03-A51A-8B2BCCBD9485的TASK_CREATED事件触发
         * 2025-05-22 13:46:30.893  INFO 24128 --- [           main] c.b.n.f.config.GlobalEventListener       : GlobalEventListener: TASK_CREATED
         * 2025-05-22 13:46:30.893  INFO 24128 --- [           main] c.b.n.f.config.GlobalEventListener       : 用户任务sid-21A14EF5-6F33-4A2F-97F5-A6FF91CE2654的TASK_CREATED事件触发
         **/
    }

    /**
     *  <h2>启用日志监听器</h2>
     *  <p>
     *      启用日志监听器，会打印所有流程事件，并打印事件触发的节点信息。具体实现步骤如下所示：
     *   <ol>
     *       <li>
     *           <b>步骤一：</b>创建日志监听器的实现类，详见：{@link FlowableLoggingListener}
     *       </li>
     *       <li>
     *           <b>步骤二：</b>开启日志监听配置以及记录配置，详见：{@link cn.blnp.net.flowable.config.FlowableConfig}
     *       </li>
     *       <li>
     *           <b>步骤三：</b>做以下配置信息：
     *       <pre>
     *           {@code
     *              flowable:
     *                  #配置说明：
     *                  #none：不记录任何历史数据
     *                  #activity：记录流程实例、活动节点、变量修改等基础信息
     *                  #audit：包含activity级数据，并额外记录任务详情、表单属性、流程定义变更
     *                  #full：记录完整的执行细节（包括变量更新日志、任务持续时间等）
     *                  history-level: AUDIT
     *              logging:
     *                  level:
     *                    cn.blnp.net.flowable.config.FlowableLoggingListener:  DEBUG
     *           }
     *       </pre>
     *       </li>
     *   </ol>
     *   开启日志监听配置后，在数据库的 act_evt_log 表中将会记录流程事件信息。如下图：
     *   <img src="https://cdn4.winhlb.com/2025/05/22/682ec3b946f7e.png" />
     *  </p>
     **/
    @Test
    public void testLogging() {
        testExample();

        /**
         *  演示结果：
         * 2025-05-22 14:17:26.572  INFO 41988 --- [           main] c.b.n.f.l.g.events.GlobalEventFlowTest   : 部署流程定义：6e3810f8-36d4-11f0-b75a-50ebf6ec8f6d
         * 2025-05-22 14:17:26.576  INFO 41988 --- [           main] c.b.n.f.l.g.events.GlobalEventFlowTest   : 流程定义编号：globalEventFlow:5:6e9fac6b-36d4-11f0-b75a-50ebf6ec8f6d
         * 2025-05-22 14:17:26.593  INFO 41988 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 流程启动 | 实例ID:6ea7267e-36d4-11f0-b75a-50ebf6ec8f6d | 定义ID:globalEventFlow:5:6e9fac6b-36d4-11f0-b75a-50ebf6ec8f6d
         * 2025-05-22 14:17:26.594 DEBUG 41988 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:startEvent | ID:startEvent1
         * 2025-05-22 14:17:26.598 DEBUG 41988 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:sid-3F4DC69F-9435-4D03-A51A-8B2BCCBD9485
         * 2025-05-22 14:17:26.619  INFO 41988 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:6eab6c42-36d4-11f0-b75a-50ebf6ec8f6d | 名称:财务审核 | 处理人:null
         * 2025-05-22 14:17:26.768 DEBUG 41988 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 节点进入 | 类型:userTask | ID:sid-21A14EF5-6F33-4A2F-97F5-A6FF91CE2654
         * 2025-05-22 14:17:26.768  INFO 41988 --- [           main] c.b.n.f.config.FlowableLoggingListener   : 任务创建 | ID:6ec24fac-36d4-11f0-b75a-50ebf6ec8f6d | 名称:行政下发 | 处理人:null
         **/
    }
}
